package com.fau.template.service.impl;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import com.fau.template.entity.TKeyValue;
import com.fau.template.service.IDictionaryManagerService;

@Service
@Transactional(readOnly = true)
public class DictionaryManagerServiceImpl extends BaseService implements IDictionaryManagerService {

	@Override
	@Transactional(readOnly = false, propagation = Propagation.REQUIRED, rollbackFor = Exception.class)
	public void save(TKeyValue key) {
		this.iBaseDao.insertObject(key);
	}

	@Override
	@Transactional(readOnly = false, propagation = Propagation.REQUIRED, rollbackFor = Exception.class)
	public void update(TKeyValue key) {
		this.iBaseDao.updateObject(key);
	}

	@Override
	@Transactional(readOnly = false, propagation = Propagation.REQUIRED, rollbackFor = Exception.class)
	public void delete(TKeyValue key) {
		String[] ids = key.getId().split("-");
		for(String id : ids) {
			this.iBaseDao.updateByHql("delete from TKeyValue t where t.id = ? ", id);
		}
	}

	@Override
	public TKeyValue getKeyValueById(String id) {
		return (TKeyValue) this.iBaseDao.getObject(TKeyValue.class, id);
	}

	
}
